#ifndef __INCLUDED_CBL_CLASSFACTORY_H__
#error "CBL_ClassFactory.hpp must not be used directly. Use CBL_ClassFactory.h instead."
#else
#ifndef __INCLUDED_CBL_CLASSFACTORY_HPP__
#define __INCLUDED_CBL_CLASSFACTORY_HPP__

template <typename TType>
CB_FORCEINLINE uint32 CB_INLINE_ATTR CClassFactory::GetClassId()
{
    const char* pClassName = RTTI::GetClassName<TType>();
    return Math::CRC32(pClassName);
}

// ------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE uint32 CB_INLINE_ATTR CClassFactory::GetClassId(TType* _pClass)
{
    const char* pClassName = RTTI::GetClassName(_pClass);
    return Math::CRC32(pClassName);
}

// ------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE const uint32 CB_INLINE_ATTR CClassFactory::RegisterClass()
{
    uint32 ClassId = GetClassId<TType>();
    CClassFactory& rClassFactory = CClassFactory::CreateInstance();
    
    Debug::Assert(rClassFactory.m_TypeMappings.find(ClassId) == rClassFactory.m_TypeMappings.end(), 
                  "ClassId name collision for \"%s\".\n", 
                  RTTI::GetClassName<TType>());
    
    rClassFactory.m_TypeMappings[ClassId] = &ClassFactoryNew<TType>;
    return ClassId;
}

// ------------------------------------------------------------------------------

CB_FORCEINLINE void* CB_INLINE_ATTR CClassFactory::NewObject(const char* _pClassName)
{
    uint32 ClassId = Math::CRC32(_pClassName, strlen(_pClassName));
    return m_TypeMappings[ClassId]();
}

#endif
#endif